package com.wutong.erb.exception.base;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 工具类异常
 *
 * @author wutong
 */
@Getter
public class UtilException extends BaseException {
    private final int code;

    private static final Map<Integer, UtilException> UTIL_EXCEPTION_MAP = new HashMap<>();

    public UtilException(int code, String message) {
        super(4L, UTIL_EXCEPTION_MAP, message);
        if (UTIL_EXCEPTION_MAP.get(code) == null) {
            UTIL_EXCEPTION_MAP.put(code, this);
        } else {
            throw new IllegalArgumentException("存在相同的异常码：" + code + "-" + UTIL_EXCEPTION_MAP.get(code).getClass().getSimpleName() + "<->" + this.getClass().getSimpleName());
        }
        this.code = code;
    }

    public UtilException getException(int code) {
        return UTIL_EXCEPTION_MAP.get(code);
    }
}
